package com.xl.cloud.netty.nio;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

/**
 * @Author XiangLiang
 * @Since 2025/1/9 14:00
 * @Description: NIOFileChannel04类 - 文件拷贝 transferFrom方法
 */
public class NIOFileChannel04 {
    public static void main(String[] args) throws Exception {
        FileInputStream fileInputStream = new FileInputStream("D:\\file01.txt");
        FileOutputStream fileOutputStream = new FileOutputStream("D:\\file03.txt");

        FileChannel fileInputChannel = fileInputStream.getChannel();
        FileChannel fileOutputChannel = fileOutputStream.getChannel();

        fileOutputChannel.transferFrom(fileInputChannel, 0, fileInputChannel.size());

        // 关闭通道和流资源
        fileInputChannel.close();
        fileOutputChannel.close();
        fileInputStream.close();
        fileOutputStream.close();
    }
}
